import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:webview_flutter/webview_flutter.dart';

class CommonWebPage extends StatefulWidget {
  final String title;
  final String url;
  final String shareContent;

  CommonWebPage({Key key, this.title, this.url, this.shareContent})
      : assert(url != null),
        super(key: key);

  @override
  _CommonWebPageState createState() => _CommonWebPageState();
}

class _CommonWebPageState extends State<CommonWebPage> {

  WebViewController _controller;// web控制器


  @override
  void initState() {
    super.initState();
    SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarBrightness: Brightness.dark,
      statusBarIconBrightness: Brightness.dark,
    );
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        elevation: 15,
        iconTheme: IconThemeData(color: Colors.black),
        centerTitle: true,
        title: Text(widget.title == null ? "" : widget.title),
        actions: <Widget>[
          Icon(Icons.share),
          SizedBox(
            width: 20,
          ),
        ],
        leading: InkWell(
          child: Icon(Icons.close),
          onTap: () => {Navigator.pop(context)},
        ),
      ),
      body: Stack(
        children: <Widget>[
          WebView(
            initialUrl: widget.url,
            // 允许js执行
            javascriptMode: JavascriptMode.unrestricted,

            // 页面创建完成
            onWebViewCreated: (controller) {
              _controller = controller;
            },
            // 页面加载结束
            onPageFinished: (url) {

            },
          ),
        ],
      ),
    );
  }
}
